﻿using LPP.Core.Services;
using LPP.Entity.Logs;
using LPP.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace LPP.Service.BusServices
{
    public class LogService : ILogService
    {
        private readonly SqlDbContext _context;

        public LogService(SqlDbContext context)
        {
            _context = context;
        }

        public async Task AddLogAsync(string message, string level)
        {
            var log = new Logs
            {
                Message = message,
                Level = level,
                Timestamp = DateTime.UtcNow
            };
            await _context.Logs.AddAsync(log);
            await _context.SaveChangesAsync();
        }

        public async Task<List<Logs>> GetAllLogsAsync()
        {
            return await _context.Logs.ToListAsync();
        }

        public async Task<Logs> GetLogByIdAsync(int id)
        {
            return await _context.Logs.FindAsync(id);
        }
    }
}
